package com.springboot.test.entity.configuartion;

import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor;
import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor;
import com.springboot.test.entity.handler.MybatisHandler;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@Slf4j
@Configuration
public class MybatisConfig {
    public MybatisConfig(){
        log.info("mybatis配置类生效");
    }

    /**
     * 主动填充字段
     * @return
     */
    @Bean
    public MetaObjectHandler metaObjectHandler(){
        return new MybatisHandler();
    }

    /**
     * 分页工具配置
     * @return
     */
    @Bean
    public MybatisPlusInterceptor mybatisPlusInterceptor(){
        MybatisPlusInterceptor mybatisPlusInterceptor = new MybatisPlusInterceptor();
        mybatisPlusInterceptor.addInnerInterceptor(new PaginationInnerInterceptor());
        return mybatisPlusInterceptor;
    }
}
